<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div class="box">
        <h1>{{num}}</h1>
        <!-- v-on:事件名='事件回调函数的名字'  -->
        <button v-on:click = 'sum'>点击该按钮加1</button>
        <button v-on:click = 'num--'>点击 -1</button>
        <button v-on:click = 'num*=2'>点击 *2</button>
        <!-- 简写 -->
        <button @click="sum">点击 +1</button>
        <!-- 传参 -->
        <button @click="testCc(10)">test 传参</button>
        <!-- 取余 -->
        <button @click="quyu">点击 取余2</button>
        <!-- 事件对象 -->
        <button @click="testEvent">test 无参event</button>
        <button @click="testEventc($event,'小名')">test 有参event</button>
    </div>
    <script>
        let vm = new Vue({
            el:'.box',
            data:{
                num:0
            },
            //事件回调函数的名字都存放在methods对象中
            methods:{
                sum(){
                    this.num ++;
                },
                testCc(a){
                    console.log(a)
                },
                quyu(){
                    this.num %= 2;//在methods中this指向实力对象
                },
                testEvent(event){
                    console.log(event)
                },
                testEventc(event,name){
                    console.log(name);
                    console.log(event)
                }
            }
        })
    </script>
</body>
</html>